package com.digitalgeko.hourreporter;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;

import com.digitalgeko.hourreporter.complements.*;
import com.digitalgeko.hourreporter.database.*;

public class CreateUserActivity extends Activity {

	private EditText user, password, confirm;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.create_user);
		initComponents();
	}
	
	private void initComponents(){
		user = (EditText)findViewById(R.id.etUser);
		password = (EditText)findViewById(R.id.etPassword);
		confirm = (EditText)findViewById(R.id.etConfirm);
	}
	
	public void registerClick(View v){
		if((user.getText().toString().length() > 0) && (password.getText().toString().length() > 0) 
				&& (confirm.getText().toString().length() > 0)){
			if(password.getText().toString().equals(confirm.getText().toString())){
				if(UserTableManager.createUser(user.getText().toString(), password.getText().toString(), this) != -1){
					Dialogs.finishDialog("Usuario creado exitosamente", this, this);
				}else{
					Dialogs.okDialog("El usuario no se ha podido registrar", this);
				}
			}else{
				Dialogs.okDialog(getString(R.string.passNotMatch), this);
			}
		}else{
			Dialogs.okDialog(getString(R.string.allFields), this);
		}
	}
	
}
